<script setup>
import { ref } from 'vue'

const collections = ref([
  {
    dynasty: '先秦',
    restored: 3,
    total: 8,
    books: [
      { 
        id: 1, 
        name: '周易', 
        year: '前1046年',
        condition: '优',
        restored: true, 
        image: 'https://pic.baike.soso.com/ugc/baikepic2/29797/20200710003707-1612295431_jpg_736_549_50965.jpg/0' 
      },
      { 
        id: 2, 
        name: '尚书', 
        year: '前800年',
        condition: '良',
        restored: true, 
        image: 'https://pic.baike.soso.com/ugc/baikepic2/12074/20200807144725-917942219_jpg_632_843_66325.jpg/0' 
      },
      { 
        id: 3, 
        name: '诗经', 
        year: '前600年',
        condition: '优',
        restored: true, 
        image: 'https://pic.baike.soso.com/ugc/baikepic2/2889/20200731161707-673352042_jpg_580_435_24444.jpg/0' 
      },
      { id: 4, name: '待修复', restored: false },
      { id: 5, name: '待修复', restored: false }
    ]
  },
  {
    dynasty: '汉代',
    restored: 2,
    total: 6,
    books: [
      { 
        id: 6, 
        name: '史记', 
        year: '前91年',
        condition: '良',
        restored: true, 
        image: 'https://pic.baike.soso.com/ugc/baikepic2/4523/20200721161454-1674262227_jpg_474_666_45588.jpg/0' 
      },
      { 
        id: 7, 
        name: '汉书', 
        year: '82年',
        condition: '优',
        restored: true, 
        image: 'https://pic.baike.soso.com/ugc/baikepic2/4523/20200721161454-1674262227_jpg_474_666_45588.jpg/0' 
      },
      { id: 8, name: '待修复', restored: false },
      { id: 9, name: '待修复', restored: false }
    ]
  }
])

const totalStats = ref({
  totalRestored: 156,
  totalBooks: 428,
  restorationRate: 36.4
})
</script>

<template>
  <div class="collection-container">
    <div class="collection-header">
      <div class="header-content">
        <h1>古籍典藏</h1>
        <div class="overall-stats">
          <div class="stat-item">
            <span class="stat-label">馆藏总数</span>
            <span class="stat-value">{{ totalStats.totalBooks }}</span>
          </div>
          <div class="stat-item">
            <span class="stat-label">已修复</span>
            <span class="stat-value">{{ totalStats.totalRestored }}</span>
          </div>
          <div class="stat-item">
            <span class="stat-label">修复率</span>
            <span class="stat-value">{{ totalStats.restorationRate }}%</span>
          </div>
        </div>
      </div>
      <div class="search-section">
        <input type="text" placeholder="搜索古籍名称、朝代..." class="search-input">
        <div class="filter-tags">
          <span class="filter-tag active">全部</span>
          <span class="filter-tag">已修复</span>
          <span class="filter-tag">待修复</span>
          <span class="filter-tag">珍品</span>
        </div>
      </div>
    </div>

    <div class="dynasty-sections">
      <div v-for="dynasty in collections" :key="dynasty.dynasty" class="dynasty-section">
        <div class="dynasty-header">
          <h2>{{ dynasty.dynasty }}</h2>
          <div class="dynasty-stats">
            <span class="restoration-rate">修复进度：{{ dynasty.restored }}/{{ dynasty.total }}</span>
            <div class="progress-bar">
              <div class="progress" :style="{ width: (dynasty.restored/dynasty.total*100) + '%' }"></div>
            </div>
          </div>
        </div>

        <div class="books-grid">
          <div 
            v-for="book in dynasty.books" 
            :key="book.id"
            class="book-item"
            :class="{ 'not-restored': !book.restored }"
          >
            <div class="book-image">
              <img v-if="book.restored" :src="book.image" :alt="book.name">
              <div v-else class="pending-restoration">待修复</div>
            </div>
            <div class="book-info">
              <h3>{{ book.name }}</h3>
              <div v-if="book.restored" class="book-meta">
                <span>年代：{{ book.year }}</span>
                <span class="condition">品相：{{ book.condition }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.collection-container {
  min-height: calc(100vh - 72px);
  padding: 0 40px;
  max-width: 1800px;
  margin: 0 auto;
}

.collection-header {
  background: white;
  border-radius: 16px;
  padding: 32px;
  margin-bottom: 40px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.collection-header h1 {
  font-size: 28px;
  color: #4a4a4a;
  font-weight: 600;
}

.overall-stats {
  display: flex;
  gap: 48px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.stat-label {
  color: #666;
  font-size: 14px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  color: #8b4513;
}

.search-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-input {
  width: 100%;
  padding: 12px 20px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.3s;
}

.search-input:focus {
  border-color: #8b4513;
}

.filter-tags {
  display: flex;
  gap: 12px;
}

.filter-tag {
  padding: 6px 16px;
  border-radius: 16px;
  background: #f5f5f5;
  color: #666;
  cursor: pointer;
  transition: all 0.3s;
}

.filter-tag:hover,
.filter-tag.active {
  background: #8b4513;
  color: white;
}

.dynasty-section {
  background: white;
  border-radius: 16px;
  padding: 32px;
  margin-bottom: 32px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.dynasty-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.dynasty-header h2 {
  font-size: 24px;
  color: #4a4a4a;
}

.dynasty-stats {
  display: flex;
  align-items: center;
  gap: 16px;
}

.restoration-rate {
  color: #666;
  font-size: 14px;
}

.progress-bar {
  width: 200px;
  height: 8px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
}

.progress {
  height: 100%;
  background: #8b4513;
  border-radius: 4px;
  transition: width 0.3s;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

.book-item {
  background: #f8f6f1;
  border-radius: 12px;
  overflow: hidden;
  transition: transform 0.3s;
}

.book-item:hover {
  transform: translateY(-4px);
}

.book-image {
  height: 200px;
  overflow: hidden;
}

.book-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pending-restoration {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eee;
  color: #999;
  font-size: 18px;
}

.book-info {
  padding: 16px;
}

.book-info h3 {
  font-size: 18px;
  color: #4a4a4a;
  margin-bottom: 8px;
}

.book-meta {
  display: flex;
  justify-content: space-between;
  color: #666;
  font-size: 14px;
}

.condition {
  color: #8b4513;
  font-weight: 500;
}

.not-restored {
  opacity: 0.7;
}

@media (min-width: 1920px) {
  .books-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 32px;
  }

  .book-image {
    height: 240px;
  }
}
</style> 